// package com.hu.auth.common.security;
//
// import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
// import com.hu.auth.common.exception.CustomerException;
// import com.hu.auth.common.result.RCodeEnum;
// import com.hu.auth.model.User;
// import com.hu.auth.service.RoleService;
// import com.hu.auth.service.UserService;
// import org.springframework.security.core.GrantedAuthority;
// import org.springframework.security.core.authority.SimpleGrantedAuthority;
// import org.springframework.security.core.userdetails.UserDetails;
// import org.springframework.security.core.userdetails.UserDetailsService;
// import org.springframework.security.core.userdetails.UsernameNotFoundException;
// import org.springframework.stereotype.Component;
//
// import javax.annotation.Resource;
// import java.util.ArrayList;
// import java.util.Collections;
// import java.util.List;
//
// @Component
// public class UserDetailServiceImpl implements UserDetailsService {
//
//     @Resource
//     UserService userService;
//     @Resource
//     RoleService roleService;
//
//     @Override
//     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//         User user = userService.getOne(new LambdaQueryWrapper<User>()
//                 .eq(User::getUsername, username));
//         if (user == null) {
//             throw new CustomerException(RCodeEnum.ACCOUNT_ERROR.getCode(), RCodeEnum.ACCOUNT_ERROR.getMessage());
//         }
//
//         // 用户权限
//         List<String> buttons = (List<String>) userService.info(user.getId()).get("buttons");
//         List<GrantedAuthority> authList = new ArrayList<>();
//         for (String button : buttons) {
//             authList.add(new SimpleGrantedAuthority(button.trim()));
//         }
//
//         return new SecurityUser(user, authList);
//     }
// }
